package com.systop.supervise.controller;
import com.systop.common.pojo.performance;
import com.systop.common.util.ResponseResult;
import com.systop.supervise.service.PerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PerformanceController {
    @Autowired
    private PerformanceService performanceService;

    //添加
    @RequestMapping(value = "/performanceadd", method = RequestMethod.POST)
    @ResponseBody
    //performance_id
    //sno,elective_course_id,tno,performance_rule_id,peacetime_performance,mid_term_performanc,final_performance,skill_assessment,total_score,pass_flag,allow_flag,remark
    public ResponseResult performanceadd(@RequestParam(value = "sno") String sno,
                                       @RequestParam(value = "elective_course_id") String elective_course_id,
                                       @RequestParam(value = "tno") String tno,
                                       @RequestParam(value = "performance_rule_id") String performance_rule_id,
                                       @RequestParam(value = "peacetime_performance") String peacetime_performance,
                                       @RequestParam(value = "mid_term_performance") String mid_term_performance,
                                       @RequestParam(value = "final_performance") String final_performance,
                                       @RequestParam(value = "skill_assessment") String skill_assessment,
                                       @RequestParam(value = "total_score") String total_score,
                                       @RequestParam(value = "pass_flag") String pass_flag,
                                       @RequestParam(value = "allow_flag") String allow_flag,
                                       @RequestParam(value = "remark") String remark) {
        performance p = new performance();
        p.setSno(sno);
        int elective_course_id1 = Integer.parseInt(elective_course_id);
        p.setElective_course_id(elective_course_id1);
        p.setTno(tno);
        int performance_rule_id1 = Integer.parseInt(performance_rule_id);
        p.setPerformance_rule_id(performance_rule_id1);
        Double peacetime_performance1 = Double.parseDouble(peacetime_performance);
        p.setPeacetime_performance(peacetime_performance1);
        Double mid_term_performanc1 = Double.parseDouble(mid_term_performance);
        p.setMid_term_performance(mid_term_performanc1);
        Double final_performance1 = Double.parseDouble(final_performance);
        p.setFinal_performance(final_performance1);
        Double skill_assessment1 = Double.parseDouble(skill_assessment);
        p.setSkill_assessment(skill_assessment1);
        Double total_score1 = Double.parseDouble(total_score);
        p.setTotal_score(total_score1);
        int pass_flag1 = Integer.parseInt(pass_flag);
        p.setPass_flag(pass_flag1);
        int allow_flag1 = Integer.parseInt(allow_flag);
        p.setAllow_flag(allow_flag1);
        p.setRemark(remark);
        List<performance> list = performanceService.performanceall();
        for (int i=0;i<list.size();i++){
            if (list.get(i).getElective_course_id() == elective_course_id1 || list.get(i).getSno() == sno){
                return  ResponseResult.build(2000,"重复添加");
            }
        }
        int i =  performanceService.performanceadd(p);
        if (i == 0) {
            return ResponseResult.build(500, "添加失败");
        } else {
            return ResponseResult.build(200, "添加成功",p);
        }
    }
    //根据id修改
    @RequestMapping(value = "/performanceUp", method = RequestMethod.POST)
    @ResponseBody
    //performance_id
    //sno,elective_course_id,tno,performance_rule_id,peacetime_performance,mid_term_performance,final_performance,skill_assessment,total_score,pass_flag,allow_flag,remark
    public ResponseResult performanceUp( @RequestParam(value = "performance_id") String performance_id,
                                         @RequestParam(value = "sno") String sno,
                                         @RequestParam(value = "elective_course_id") String elective_course_id,
                                         @RequestParam(value = "tno") String tno,
                                         @RequestParam(value = "performance_rule_id") String performance_rule_id,
                                         @RequestParam(value = "peacetime_performance") String peacetime_performance,
                                         @RequestParam(value = "mid_term_performance") String mid_term_performance,
                                         @RequestParam(value = "final_performance") String final_performance,
                                         @RequestParam(value = "skill_assessment") String skill_assessment,
                                         @RequestParam(value = "total_score") String total_score,
                                         @RequestParam(value = "pass_flag") String pass_flag,
                                         @RequestParam(value = "allow_flag") String allow_flag,
                                         @RequestParam(value = "remark") String remark) {
        performance p = new performance();
        int performance_id1 = Integer.parseInt(performance_id);
        p.setPerformance_id(performance_id1);
        p.setSno(sno);
        int elective_course_id1 = Integer.parseInt(elective_course_id);
        p.setElective_course_id(elective_course_id1);
        p.setTno(tno);
        int performance_rule_id1 = Integer.parseInt(performance_rule_id);
        p.setPerformance_rule_id(performance_rule_id1);
        Double peacetime_performance1 = Double.parseDouble(peacetime_performance);
        p.setPeacetime_performance(peacetime_performance1);
        Double mid_term_performanc1 = Double.parseDouble(mid_term_performance);
        p.setMid_term_performance(mid_term_performanc1);
        Double final_performance1 = Double.parseDouble(final_performance);
        p.setFinal_performance(final_performance1);
        Double skill_assessment1 = Double.parseDouble(skill_assessment);
        p.setSkill_assessment(skill_assessment1);
        Double total_score1 = Double.parseDouble(total_score);
        p.setTotal_score(total_score1);
        int pass_flag1 = Integer.parseInt(pass_flag);
        p.setPass_flag(pass_flag1);
        int allow_flag1 = Integer.parseInt(allow_flag);
        p.setAllow_flag(allow_flag1);
        p.setRemark(remark);
        int i =  performanceService.performanceUp(p);
        if (i == 0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功",p);
        }
    }
    // 2通过tno查list
    @RequestMapping(value = "/performancetno", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult performancetno(@RequestParam(value = "tno") String tno){
        List<performance> list = performanceService.performancetno(tno);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //3通过成绩id 查list
    @RequestMapping(value = "/performance_id_list", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult performance_id_list(@RequestParam(value = "performance_id") String performance_id){
        int performance_id1 = Integer.parseInt(performance_id);
        List<performance> list = performanceService.performance_id_list(performance_id1);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //3-1通过成绩id 查 实体
    @RequestMapping(value = "/performance_id_p", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult performance_id_p(@RequestParam(value = "performance_id") String performance_id){
        int performance_id1 = Integer.parseInt(performance_id);
        performance per = performanceService.performance_id_p(performance_id1);
        if (per == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",per);
        }
    }
    //3-2通过排课id查list
    @RequestMapping(value = "/paikeId_tno", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult paikeId_tno(@RequestParam(value = "elective_course_id") String elective_course_id){
        int elective_course_id1 = Integer.parseInt(elective_course_id);
        List<performance> list = performanceService.paikeId_tno(elective_course_id1);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //5通过sno和排课id和状态sno elective_course_id allow_flag
    @RequestMapping(value = "/sno_pkid_allow", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult sno_pkid_allow(@RequestParam(value = "sno") String sno,@RequestParam(value = "elective_course_id") String elective_course_id,@RequestParam(value = "allow_flag") String allow_flag){
        performance p = new performance();
        p.setSno(sno);
        int elective_course_id1 = Integer.parseInt(elective_course_id);
        p.setElective_course_id(elective_course_id1);
        int allow_flag1 = Integer.parseInt(allow_flag);
        p.setAllow_flag(allow_flag1);
        List<performance> list = performanceService.sno_pkid_allow(p);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //6通过tno修改 发布成绩
    @RequestMapping(value = "/allow_flagfabu", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult allow_flagfabu(@RequestParam(value = "tno") String tno,@RequestParam(value = "allow_flag") String allow_flag){
        performance p = new performance();
        p.setTno(tno);
        int allow_flag1 = Integer.parseInt(allow_flag);
        p.setAllow_flag(allow_flag1);
        int i = performanceService.allow_flagfabu(p);
        if (i==0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功",i);
        }
    }
    //查询全部 performanceall
    @RequestMapping(value = "/performanceall", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult performanceall(){
        List<performance> list = performanceService.performanceall();
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    // 6通过id删除 performancedel
    @RequestMapping(value = "/performancedel", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult performancedel(@RequestParam(value = "performance_id") String performance_id){
        int performance_id1 = Integer.parseInt(performance_id);
       int i = performanceService.performancedel(performance_id1);
        if (i == 0) {
            return ResponseResult.build(500, "删除失败");
        } else {
            return ResponseResult.build(200, "删除成功",i);
        }
    }





}
